package luj.game.robot.internal.instance.boss.command.service;

import luj.bean.api.BeanContext;
import luj.cluster.api.actor.Tellable;
import luj.game.robot.api.action.CommandService;
import luj.game.robot.internal.instance.boss.command.map.BossCommandMap;

import static com.google.common.base.Preconditions.checkNotNull;

public class BossServiceFactory {

  public BossServiceFactory(Tellable bossRef, BeanContext lujbean, BossCommandMap commandMap, Class<?> cmdType) {
    _bossRef = bossRef;
    _lujbean = lujbean;
    _commandMap = commandMap;
    _cmdType = cmdType;
  }

  public <P> CommandService<P> create() {
    String cmdName = _cmdType.getName();
    BossCommandMap.Cmd cmd = _commandMap.get(cmdName);
    checkNotNull(cmd, cmdName);

    var service = new ServiceBoss<P>();
    service._cmd = cmd;
    service._factory = this;

    return service;
  }

  final Tellable _bossRef;
  final BeanContext _lujbean;

  private final BossCommandMap _commandMap;
  private final Class<?> _cmdType;
}
